/**
 * PackfactoryEmployServiceImpl.java
 * Created at 2017-3-2
 * Created by shihui
 * Copyright (C) 2017 BROADTEXT SOFTWARE, All rights reserved.
 */
package com.broadtext.rms.basic.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.broadtext.common.bean.EntityPageBean;
import com.broadtext.common.exp.DaoException;
import com.broadtext.common.exp.ServiceException;
import com.broadtext.common.repository.EntityDao;
import com.broadtext.common.service.impl.EntityServiceImpl;
import com.broadtext.rms.basic.model.TmPackfactoryEmploy;
import com.broadtext.rms.basic.service.IPackfactoryEmployService;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;

/**
 * <p>ClassName: PackfactoryEmployServiceImpl</p>
 * <p>Description: 客户联系人服务层</p>
 * <p>Author: shihui</p>
 * <p>Date: 2017-3-2</p>
 */
@Service("packfactoryEmployServiceImpl")
public class PackfactoryEmployServiceImpl extends EntityServiceImpl<TmPackfactoryEmploy> implements IPackfactoryEmployService {
    
    /**
     * <p>
     * Description: 注解入相关DAO
     * </p>
     * 
     * @param entityDao
     */
    @Autowired
    @Qualifier("tmPackfactoryEmployDao")
    public void setEntityDao(EntityDao<TmPackfactoryEmploy> entityDao) {
        super.entityDao = entityDao;
    }

    /**
     * 
     * <p>Description: 查询生产厂人员记录</p>
     * @param map 查询条件
     * @param pageBounds 翻页信息
     * @return 查询结果
     * @throws ServiceException 异常
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @Override
    public EntityPageBean<Object> getFactoryEmploys(Map<String, Object> map, PageBounds pageBounds) throws ServiceException {
        EntityPageBean pb;
        pb = new EntityPageBean();
        try {
            pb = this.entityDao.findEntityPageByProperty("com.broadtext.rms.basic.model.TmPackfactoryEmploy.findEmploys",
                    map, pageBounds);
        } catch (DaoException e) {
            throw new ServiceException(e);
        }
        return pb;
    }

    /**
     * 
     * <p>Description: 根据id删除人员</p>
     * @param idArray id数组
     * @param sysUser 操作用户
     * @throws ServiceException 异常
     */
    @Override
    public void deleteEmployByIds(String[] idArray, String sysUser) throws ServiceException {
        for (String id : idArray) {
            TmPackfactoryEmploy emp;
            emp = new TmPackfactoryEmploy();
            emp = this.findEntityById(id);
            if (emp != null) {
                emp.setDelFlag("1");
                emp.setUpdateUser(sysUser);
                emp.setUpdateDate(new Date());
                super.updateRecord(emp);
            }
        }
    }

    /**
     * 
     * <p>Description: 查询生产厂人员详情</p>
     * @param pkId 人员ID
     * @return 人员详情
     * @throws ServiceException 异常
     */
    @SuppressWarnings("unchecked")
    @Override
    public Object findEmployInfoById(String pkId) throws ServiceException {
        List<Object> list;
        list = new ArrayList<Object>();
        try {
            list = this.entityDao.findByProperty("com.broadtext.rms.basic.model.TmPackfactoryEmploy.getEmployInfo", pkId);
            if (list.size() != 0) {
                return list.get(0);
            }
        } catch (DaoException e) {
            throw new ServiceException(e);
        }
        return null;
    }

    /**
     * 
     * <p>Description: 页面归属厂下拉框数据查询</p>
     * @return 归属厂数据
     * @throws ServiceException 异常
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Object> findFactory() throws ServiceException {
        List<Object> list;
        list = new ArrayList<Object>();
        try {
            //临时
            list = this.entityDao.findByProperty("com.broadtext.rms.basic.model.TmPackfactoryEmploy.findPackFactoryOpt", null);
        } catch (DaoException e) {
            try {
                throw new ServiceException(e);
            } catch (ServiceException e1) {
                throw new ServiceException(e);
            }
        }
        return list;
    }

    /**
     * 
     * <p>Description: 验证操作删除人员是否已绑定用户</p>
     * @param idArray 人员ID
     * @return 验证结果:true-已绑定；false-未绑定
     * @throws ServiceException 异常
     */
    @SuppressWarnings("rawtypes")
    @Override
    public boolean checkUserBind(String[] idArray) throws ServiceException {
        List user;
        for (String id : idArray) {
            try {
                user = this.entityDao.findByProperty("com.broadtext.rms.system.model.SysUser.findByUserId", id);
                if (user.size() != 0) {
                    return true;
                }
            } catch (DaoException e) {
                throw new ServiceException(e);
            }
        }
        return false;
    }
}
